package com.zbs.framework.common.utils;

import org.reflections.Reflections;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class IErrorUtil {
    public static Map<String,String> getErrorStatus(Class<?> ...clazz) {
        Object[] objects = Arrays.stream(clazz).map(Class::getName).collect(Collectors.toList()).toArray(new Object[]{});
        Reflections reflections = new Reflections(objects);

        Set<Class<? extends IError>> monitorClasses = reflections.getSubTypesOf(IError.class);
        Map<String,String> map = new HashMap<>();
        monitorClasses.forEach(m->{
            try {
                IError[] enumConstants = m.getEnumConstants();
                for (IError anEnum : enumConstants) {
                    map.put(anEnum.getErrMsg(), anEnum.getErrCode().toString());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        return map;
    }
}
